﻿#pragma once
#include <qwidget>
#include <vector>
#include <qplaintextedit>
#include <opencv2/opencv.hpp>

class QLineEdit;
class QPushButton;
class QGroupBox;
//class QPlainTextEdit;

enum obj_type{image_type=0,video_type,text_type,nature_language_type};

class VisionMainWnd;
class InferMainWin :
    public QWidget
{
    Q_OBJECT
public:
    InferMainWin(QWidget *parent = nullptr);
    ~InferMainWin();
    void initLayout();

    void threadInferVideo();

    void updateUI(int userType);

protected:
    void enableCtrls(bool enable);
    void writeInfos();

    void readCfgInfos();

    void setObjType(obj_type obj) { pro_obj_type_ = obj; }
    obj_type getObjType() { return pro_obj_type_; }

public slots:
    void on_loadModel();
    void on_loadPic();
    void on_loadClassess();

    void showAndHideLog();

    void on_clearLogs();

    void on_infer();
    void on_stopInfer();
    void on_setInferParams();

    void on_update_ui(std::string modelPath, std::string labelPath, double confidence, double score, double nms);
    void on_stop_machine();
    void on_start_machine();

signals:
    void setProduct(double);
    void send_Image(QImage img);
    void setParams();

private:
    cv::Mat loadImage_;
    cv::VideoCapture video_;
    bool isProcessing_ = false;
    obj_type pro_obj_type_ = image_type;
    VisionMainWnd* mainWin_ = nullptr;

    int debugFps_ = 25;

    QLineEdit* modelConfidence_ = nullptr;
    QLineEdit* modelScore_ = nullptr;
    QLineEdit* modelNMS_ = nullptr;

    QLineEdit* modelPath_ = nullptr;
    QLineEdit* classesPath_ = nullptr;
    QLineEdit* picPath_ = nullptr;

    QGroupBox* boxLoadVideoGroup_ = nullptr;
    QGroupBox* boxLoadModel_ = nullptr;
    QGroupBox* boxInferParams_ = nullptr;
};

